package com.ptu.spzx.manager.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ptu.spzx.model.dto.system.SysUserDto;
import com.ptu.spzx.model.entity.system.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {
    @Select("SELECT * FROM sys_user WHERE user_name=#{userName} AND is_deleted=0")
    SysUser selectByUserName(String userName);

    @Select("SELECT * FROM sys_user WHERE stu_id=#{stuId} AND is_deleted=0")
    List<SysUser> selectByStuId(String stuId);

    List<SysUser> findByPage(SysUserDto sysUserDto);

    void saveSysUser(SysUser sysUser);

    void updateSysUser(SysUser sysUser);

    void deleteSysUser(Long userId);

    List<SysUser> findByPageAul(SysUserDto sysUserDto);

    @Update(" update sys_user set class_name=#{className} where stu_id = #{stuId}")
    void setClassId(String stuId, String className);

    @Select("SELECT * FROM sys_user WHERE stu_id=#{stuId}")
    SysUser getStu(String stuId);

    @Select("SELECT * FROM sys_user WHERE class_name=#{className}}")
    List<SysUser> getStus(String className);

    @Select("SELECT stu_id FROM sys_user WHERE class_name=#{className} AND is_deleted=0")
    List<String> getStuListByClass(String className);

    @Update("UPDATE sys_user set class_name=null where class_name=#{className}")
    void setClaaNull(String className);

    @Select("SELECT * FROM sys_user WHERE stu_id=#{stuId} AND is_deleted=0")
    List<SysUser> getStuListByStuId(String stuId);

    @Select("SELECT * FROM sys_user WHERE user_name=#{userName}")
    SysUser selectByUsername(String username);
}
